
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;

public class TestForm extends Form implements CommandListener{
	private Display display;
	private AppMIDlet midlet;
	private Command exit, test, showalert, canvas, ok;
	private TextField in, out;
	private Alert alert;
	private String s;
	private char[] ch;
	public TestForm(AppMIDlet midlet, Display display){
		super("TestForm");
		this.midlet = midlet;
		this.display = display;
		s = "";	
		ch = new char[1];
		exit = new Command("Exit", Command.EXIT, 0);
		test = new Command("TestCommand", Command.OK, 2);
		showalert = new Command("Show Alert", Command.OK, 2);
		canvas = new Command("Canvas", Command.OK, 2);
		ok = new Command("OK", Command.OK, 0);
		in = new TextField("ASCIICode","",4,TextField.NUMERIC);
		out = new TextField("Character", "", 4, TextField.ANY);
		append(in);
		append(out);
		addCommand(ok);
		addCommand(exit);
		addCommand(canvas);		
		addCommand(showalert);		
		addCommand(test);
		setCommandListener(this);
	}
	public void commandAction(Command c, Displayable d){
		if(c == exit)
			midlet.Exit();
		if(c == canvas)
			midlet.showCanvas();
		if(c == showalert)
			display.setCurrent(alert, this);
		if(c == ok){						
			ch[0] = (char)Integer.parseInt(in.getString());
			s = new String(ch);
			out.setString(s);
			alert = new Alert ("Alert Title",s, null, AlertType.INFO);
			alert.setTimeout(5000);
			removeCommand(test);
			test = new Command(s,Command.OK, 2);
			addCommand(test);
			append(s);
		}
	}
}